
$(function(){FastClick.attach(document.body)});

	//滑动初始化
	var slideInit=function(obj){
		obj=$(obj);
		var w=window.innerWidth,con=obj.find('.slide-con'),n=obj.find('li').size(),sl=obj.find('.slide-left'),sr=obj.find('.slide-right'),p=obj.find('.slide-point'),i=0;
		var slideAuto=function(){
			p.find('i').removeClass('current').eq(i).addClass('current');
			con.animate({left:-w*i},'600','ease-out');
		};
		con.css('width',n*w),con.find('li').css('width',w);
		
		sr.bind('tap',function(){			
			++i>=n?(i=(n-1)):'';			
			slideAuto();
		});
		sl.bind('tap',function(){			
			--i<0?(i=0):'';			
			slideAuto();
		});
		con.bind('swipeLeft',function(e){
			++i>=n?(i=(n-1)):'';			
			slideAuto();
		});
		con.bind('swipeRight',function(e){
			--i<0?(i=0):'';			
			slideAuto();
		});	
	};	
	slideInit('.slides');


	//提交失败弹窗
	function alertSuccess(s){
		var html='<div class="layer-message"><div class="message-success">'+s+'<i class="icon-remove-sign"></i></div></div>';
		$(document.body).append(html);	
	}

	//提交失败弹窗
	function alertWarm(s){
		var html='<div class="layer-message"><div class="message-warm">'+s+'<i class="icon-remove-sign"></i></div></div>';
		$(document.body).append(html);	
	}

	function submit(){
		alertSuccess('恭喜您，预约成功');
		//alertWarm('请填写完整信息，谢谢');		
	}

	function showLoading(){
        var html = '<div class="loading-bg"><span></span></div>';
        $(document.body).append(html);
    }

    function hideLoading(){
        var loading=$('.loading-bg');
        loading.remove();
    }

	//下拉菜单
	$('.selectWraper').bind('tap',function(){
		var _this=$(this),opt=_this.find('.select-option'),sv=_this.find('.select-value'),icon=_this.find('i'),ih=_this.find('input');
		opt.show(),icon.removeClass().addClass('icon-chevron-up');
		opt.bind('tap',function(e){
			var t=e.target,v=t.getAttribute('data-value');
			ih.attr('value',v),sv.html(t.textContent),icon.removeClass().addClass('icon-chevron-down'),opt.hide();
			e.returnValue=false;e.stopPropagation();			
		});
	});
	
	//弹出层移除事件
	$('.layer-message i').live('tap',function(){		
		var p=$(this).parents('.layer-message');
		p.remove();		
	})
	
		
		
	
	
	//我的体检报告项目切换
	$(".tab-h a").bind("tap",function(){
		var i=$(this).index();	
		$(".tab-h a").removeClass('current').eq(i).addClass('current');
		$(".tab-con >div").hide().eq(i).show();		
	});
	
	//体检报告项目结果展开、关闭
	$(".result-item .result-h").bind('tap',function(){
		$(this).find("b,i").toggleClass('down');
		$(this).parent().find(".result-con").toggle();
	});



	//日历 依赖于zepto.js	
	function calendarHTML(n,sw,td){
		console.log('本月共'+n+'天，今日'+td+'号,本月第一天是星期'+sw);
		var t=new Date(),i=1,j=1,no=24;
		var html='<div class="calendar-wraper-bg"><div class="calendar-wraper"><div class="calendar-head"><a href="javascript:;" class="calendar-pre"><i class=" icon-caret-left"></i></a><a href="javascript:;" class="calendar-next"><i class=" icon-caret-right"></i></a><div class="calendar-title">2015年5月</div></div><div class="calendar-con-week"><a href="javascript:;">一</a> <a href="javascript:;">二</a> <a href="javascript:;">三</a> <a href="javascript:;">四</a> <a href="javascript:;">五</a> <a href="javascript:;">六</a> <a href="javascript:;">日</a></div><div class="calendar-con-day">';
			for(;j<sw;j++,i++){
				html+='<span></span>'
			}
			for(;i<=td;i++){
				html+='<span '+(td==i?'class="current"':'')+'>'+i+'</span>';
			}
			for(;i<=n;i++){
				html+='<a href="javascript:;" '+(no==i?'class="disable"':'')+'>'+i+'</a>';
			}
			html+='</div></div></div>';
			return html;
	}
	function getFormatDate(date){
		return date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate();
	}
	function getDays(date){
		var y=date.getFullYear(),m=date.getMonth()+1,t=new Date(y,m,0);
		return t.getDate();		
	}
	function getStarWeek(date){
		var y=date.getFullYear(),m=date.getMonth(),t=new Date(y,m,1);
		console.log(t.toLocaleDateString())
		return t.getDay();
	}
	function MyCalendar(str){
		var cinput=$(str),pre=$('.calendar-head .calendar-pre'),next=$('.calendar-head .calendar-next'),title=$('.calendar-head .calendar-title'),day=$('.calendar-con-day');
		var time=new Date(),days=getDays(time),startweek=getStarWeek(time),today=time.getDate();		
		cinput.bind('focus',function(){
			$(document.body).append(calendarHTML(days,startweek,today));
		})
		
	}
	
	MyCalendar('.calendar-input');

	
